/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.vaux.sc2gears.skill;

import hu.belicza.andras.sc2gearspluginapi.GeneralServices;
import hu.belicza.andras.sc2gearspluginapi.api.sc2replay.IGameEvents;
import hu.belicza.andras.sc2gearspluginapi.api.sc2replay.IPlayer;
import hu.belicza.andras.sc2gearspluginapi.api.sc2replay.IReplay;
import hu.belicza.andras.sc2gearspluginapi.api.sc2replay.ReplayConsts.ActionType;
import hu.belicza.andras.sc2gearspluginapi.api.sc2replay.action.IAction;
import java.util.Set;

/**
 *
 * @author medv4380
 */
public class ReplayData {

    static final int MaxNumberOfMin = 30;
    int ApMbyTime[] = new int[MaxNumberOfMin];
    int EApMbyTime[] = new int[MaxNumberOfMin];

    public ReplayData(IReplay replay, Set<String> watchedPlayerSet, GeneralServices gs) {
        IPlayer players[] = replay.getPlayers();

        for (int PlayerCTR = 0; PlayerCTR < players.length; PlayerCTR++) {
            if (watchedPlayerSet.contains(players[PlayerCTR].getPlayerId().getFullName())) {
                IGameEvents events = replay.getGameEvents();
                IAction actions[] = events.getActions();
                int LastMin = 0;
                for (int ActionCTR = 0; ActionCTR < actions.length; ActionCTR++) {
                    if (actions[ActionCTR].getActionType() != ActionType.INACTION) {
                        String time = gs.getReplayUtilsApi().formatFramesShort(actions[ActionCTR].getFrame(), replay.getGameSpeed());
                        time = (time.split(":"))[0];
                        LastMin = Integer.parseInt(time);

                        ApMbyTime[LastMin]++;

                        if (LastMin < MaxNumberOfMin) {
                            if (gs.getEapmUtilsApi().isActionEffective(actions, ActionCTR)) {
                                EApMbyTime[LastMin]++;
                            }
                        }
                    }
                }

                ApMbyTime[LastMin] = 0;
                EApMbyTime[LastMin] = 0;
            }
        }
    }
}
